package com.kk.xhr.model.assembler;

import com.kk.xhr.common.pojo.ApplyStatusEnum;
import com.kk.xhr.common.pojo.LeaveTypeEnum;
import com.kk.xhr.model.dto.LeaveDTO;
import com.kk.xhr.model.entity.LeaveTime;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 请假数据转换工具类
 *
 * @author kkmystery
 * @version 1.0 2021/3/1
 * @since 1.0.0
 */
@Mapper(componentModel = "spring")
public interface LeaveStructKit {

    LeaveStructKit INSTANCE = Mappers.getMapper(LeaveStructKit.class);

    /**
     * dto -> entity
     *
     * @param dto dto
     * @return entity
     */
    LeaveTime toEntity(LeaveDTO dto);

    /**
     * entity -> dto
     *
     * @param entity entity
     * @return dto
     */
    LeaveDTO toDto(LeaveTime entity);

    default ApplyStatusEnum applyStatusConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return ApplyStatusEnum.from(status);
    }

    default Byte applyStatusConvertor(ApplyStatusEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }

    default LeaveTypeEnum typeConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return LeaveTypeEnum.from(status);
    }

    default Byte typeConvertor(LeaveTypeEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }
}
